#include <cstdio>
#include <cstring>
const int maxn=200007;
struct data
{
	int max,l,r;
}tree[maxn*3];
int N,Q,ma,mi;
int h[maxn];
int max(int x,int y)
{
	return x>y?x:y;
}
int min(int x,int y)
{
	return x<y?x:y;
}
void buildtree(int left,int right,int u)
{
	tree[u].l=left;
	tree[u].r=right;
	if(left==right)
	{
		tree[u].max=h[left];
		return ;
	}
	int mid=(left+right)>>1;
	buildtree(left,mid,u<<1);
	buildtree(mid+1,right,(u<<1)+1);
	//tree[u].min=min(tree[u<<1].min,tree[(u<<1)+1].min);
	tree[u].max=max(tree[u<<1].max,tree[(u<<1)+1].max);
}
void query(int left,int right,int u)
{
	if(tree[u].l==left&&tree[u].r==right)
	{
		ma=max(ma,tree[u].max);
		//mi=min(mi,tree[u].min);
		return ;
	}
	if(left<=tree[u<<1].r)
	{
		int p=min(right,tree[u<<1].r);
		query(left,p,u<<1);
	}
	if(right>=tree[(u<<1)+1].l)
	{
		int p=max(left,tree[(u<<1)+1].l);
		query(p,right,(u<<1)+1);
	}
}
void change(int pos,int value,int u)
{
	if(pos==tree[u].l&&pos==tree[u].r)
	{
		tree[u].max=value;
		return;
	}
	if(tree[2*u].r>=pos)change(pos,value,2*u);
	else change(pos,value,2*u+1);
	tree[u].max=max(tree[u*2].max,tree[u*2+1].max);
}			
int main()
{
	freopen("test.in","r",stdin);
	int a,b;
	while(scanf("%d%d",&N,&Q)!=EOF)
	{
		for(int i=1;i<=N;i++)
			scanf("%d",&h[i]);
		buildtree(1,N,1);
		while(Q--)
		{	
			
			char ch;
			scanf("%c%c%d%d",&ch,&ch,&a,&b);
			ma=0;
			if(ch=='Q')
			{
				query(a,b,1);
				printf("%d\n",ma);
			}
			else
			{	h[a]=b;
				change(a,b,1);
			}
		}
	}
	return 0;
}
